import 'package:flutter/material.dart';
import './AddressList.dart';

// 有状态组件
class AddressPage extends StatefulWidget {
  @override
  _AddressPageState createState() => _AddressPageState();
}

// 状态管理器
class _AddressPageState extends State<AddressPage> {
  String _ads = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('获取地址')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              child: Text("请点击"),
              // onPressed: () async {
              //   var res = await Navigator.of(context)
              //       .push(MaterialPageRoute(builder: (BuildContext context) {
              //     return AddressList();
              //   }));

              //   setState(() {
              //    _ads =  res;
              //   });
              // },

              onPressed: (){
                Navigator.of(context).push(MaterialPageRoute(
                  builder: (BuildContext context){
                    return AddressList();
                  }
                )).then((res){
                  setState(() {
                    _ads = res;
                  });
                });
                
              },
            ),
            Text("${_ads.length == 0 ? '没有收货地址' : _ads}")
          ],
        ),
      ),
    );
  }
}
